<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\SearchRequest;
use App\Repositories\SearchRepository;
use Illuminate\Support\Facades\Storage;
use Zend\Diactoros\Response\JsonResponse;


/**
 * @resource 搜索
 * Class SearchController
 * @package App\Http\Controllers\Api
 */
class SearchController extends Controller
{

    /**
     * 搜索国旗
     *
     * @param SearchRequest $request
     * @param SearchRepository $searchRepository
     * @return JsonResponse
     */
    public function flag(SearchRequest $request, SearchRepository $searchRepository)
    {
        $result = $searchRepository->search($request->input('query'), 'flag');
        return new JsonResponse($result ? [
            'flag' => asset_url($result->value)
        ] : []);
    }
}
